home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / gtlayout-source.lha / LTP_LevelImage.c < prev    next >
C/C++ Source or Header  |  1995-04-03  |  11KB  |  472 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. #ifdef DO_LEVEL_KIND
  10. VOID __regargs
  11. LTP_DrawLevelImageLeft(struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,struct Image *Image,WORD Left,WORD Top,WORD Width,WORD Height,WORD OffsetX,WORD OffsetY)
  12. {
  13.     WORD    BorderTop    = Level -> KnobTop,
  14.         BorderLeft    = Level -> KnobWidth;
  15.  
  16.     Left    += OffsetX;
  17.     Top    += OffsetY;
  18.  
  19.     if(Width > 0)
  20.     {
  21.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  22.  
  23.         Move(RPort,Left,Top);
  24.         Draw(RPort,Left,Top + Height - 1);
  25.  
  26.         if(Width > 1)
  27.         {
  28.             Move(RPort,Left + 1,Top);
  29.             Draw(RPort,Left + 1,Top + Height - 2);
  30.  
  31.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  32.  
  33.             WritePixel(RPort,Left + 1,Top + Height - 1);
  34.  
  35.             if(Width > 2)
  36.             {
  37.                 Move(RPort,Left + 2,Top + Height - 1);
  38.                 Draw(RPort,Left + Width - 1,Top + Height - 1);
  39.  
  40.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  41.  
  42.                 Move(RPort,Left + 2,Top);
  43.                 Draw(RPort,Left + Width - 1,Top);
  44.  
  45.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[FILLPEN]);
  46.  
  47.                 RectFill(RPort,Left + 2,Top + 1,Left + Width - 1,Top + Height - 2);
  48.             }
  49.         }
  50.  
  51.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  52.  
  53.         RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top - 1);
  54.         RectFill(RPort,Left,Top + Height,Left + Width - 1,Top + Height + BorderTop - 1);
  55.         RectFill(RPort,Left - BorderLeft,Top - BorderTop,Left - 1,Top + Height + BorderTop - 1);
  56.     }
  57.     else
  58.     {
  59.         if(Level -> Position < BorderLeft)
  60.         {
  61.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  62.  
  63.             Left    = Image -> LeftEdge + OffsetX;
  64.             Width    = Level -> Position;
  65.  
  66.             if(Width > 0)
  67.                 RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top + Height + BorderTop - 1);
  68.         }
  69.     }
  70. }
  71.  
  72.  
  73. /*****************************************************************************/
  74.  
  75.  
  76. VOID __regargs
  77. LTP_DrawLevelImageRight(struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,struct Image *Image,WORD Left,WORD Top,WORD Width,WORD Height,WORD OffsetX,WORD OffsetY)
  78. {
  79.     WORD    BorderTop    = Level -> KnobTop,
  80.         BorderLeft    = Level -> KnobWidth;
  81.  
  82.     Left    += OffsetX;
  83.     Top    += OffsetY;
  84.  
  85.     if(Width > 0)
  86.     {
  87.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  88.  
  89.         Move(RPort,Left + Width - 1,Top);
  90.         Draw(RPort,Left + Width - 1,Top + Height - 1);
  91.  
  92.         if(Width > 1)
  93.         {
  94.             Move(RPort,Left + Width - 2,Top + 1);
  95.             Draw(RPort,Left + Width - 2,Top + Height - 1);
  96.  
  97.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  98.  
  99.             WritePixel(RPort,Left + Width - 2,Top);
  100.  
  101.             if(Width > 2)
  102.             {
  103.                 Move(RPort,Left,Top);
  104.                 Draw(RPort,Left + Width - 3,Top);
  105.  
  106.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  107.  
  108.                 Move(RPort,Left,Top + Height - 1);
  109.                 Draw(RPort,Left + Width - 3,Top + Height - 1);
  110.  
  111.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  112.  
  113.                 RectFill(RPort,Left,Top + 1,Left + Width - 3,Top + Height - 2);
  114.             }
  115.         }
  116.  
  117.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  118.  
  119.         RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top - 1);
  120.         RectFill(RPort,Left,Top + Height,Left + Width - 1,Top + Height + BorderTop - 1);
  121.         RectFill(RPort,Left + Width,Top - BorderTop,Left + Width + BorderLeft - 1,Top + Height + BorderTop - 1);
  122.     }
  123.     else
  124.     {
  125.         Width = Image -> Width - (Level -> Position + 2 * BorderLeft);
  126.  
  127.         if(Width > 0)
  128.         {
  129.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  130.  
  131.             Left = Image -> LeftEdge + OffsetX + 2 * BorderLeft + Level -> Position;
  132.  
  133.             if(Width > 0)
  134.                 RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top + Height + BorderTop - 1);
  135.         }
  136.     }
  137. }
  138.  
  139.  
  140. /*****************************************************************************/
  141.  
  142.  
  143. VOID __regargs
  144. LTP_DrawLevelImageKnob(struct RastPort *RPort,struct DrawInfo *DrawInfo,WORD Left,WORD Top,WORD Width,WORD Height,LevelImageInfo *Level,BOOL Selected)
  145. {
  146.     UWORD    Shine    = DrawInfo -> dri_Pens[SHINEPEN],
  147.         Shadow    = DrawInfo -> dri_Pens[SHADOWPEN],
  148.         Fill    = Selected ? DrawInfo -> dri_Pens[FILLPEN] : DrawInfo -> dri_Pens[BACKGROUNDPEN],
  149.         Back    = DrawInfo -> dri_Pens[BACKGROUNDPEN];
  150.  
  151.     Width = Level -> KnobWidth * 2;
  152.  
  153.     Left += Level -> Position - Level -> KnobWidth;
  154.  
  155.     if((Fill == Shine || Fill == Shadow) && Fill != Back)
  156.         Shine = Shadow = Back;
  157.  
  158.     LTP_SetAPen(RPort,Fill);
  159.  
  160.     RectFill(RPort,Left + 2,Top + 1,Left + 2 + Width - 3,Top + Height - 1);
  161.  
  162.     LTP_SetAPen(RPort,Shine);
  163.  
  164.     Move(RPort,Left + 1,Top + 1);
  165.     Draw(RPort,Left + 1,Top + Height - 2);
  166.     Draw(RPort,Left,Top + Height - 1);
  167.     Draw(RPort,Left,Top);
  168.     Draw(RPort,Left + Width - 2,Top);
  169.  
  170.     Move(RPort,Left + Width / 2,Top + 2);
  171.     Draw(RPort,Left + Width / 2,Top + Height - 3);
  172.  
  173.     LTP_SetAPen(RPort,Shadow);
  174.  
  175.     Move(RPort,Left + Width - 2,Top + Height - 2);
  176.     Draw(RPort,Left + Width - 2,Top + 1);
  177.     Draw(RPort,Left + Width - 1,Top);
  178.     Draw(RPort,Left + Width - 1,Top + Height - 1);
  179.     Draw(RPort,Left + 1,Top + Height - 1);
  180.  
  181.     Move(RPort,Left + Width / 2 - 1,Top + 2);
  182.     Draw(RPort,Left + Width / 2 - 1,Top + Height - 3);
  183. }
  184.  
  185.  
  186. /*****************************************************************************/
  187.  
  188.  
  189. VOID __regargs
  190. LTP_DrawLevelImageComplete(struct Image *Image,struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,WORD OffsetX,WORD OffsetY,BOOL Selected)
  191. {
  192.     WORD    BorderTop    = Level -> KnobTop,
  193.         BorderLeft    = Level -> KnobWidth,
  194.         Left,Top,
  195.         Width,Height;
  196.     LONG    Position;
  197.  
  198.     Left    = Image -> LeftEdge + BorderLeft;
  199.     Top    = Image -> TopEdge + BorderTop;
  200.     Width    = Image -> Width - 2 * BorderLeft;
  201.     Height    = Image -> Height - 2 * BorderTop;
  202.  
  203.     Position = Level -> Position + Left;
  204.  
  205.     SetAfPt(RPort,NULL,0);
  206.  
  207.     LTP_DrawLevelImageKnob(RPort,DrawInfo,Image -> LeftEdge + BorderLeft + OffsetX,Image -> TopEdge + OffsetY,Image -> Width - 2 * BorderLeft,Image -> Height,Level,Selected);
  208.     LTP_DrawLevelImageLeft(RPort,DrawInfo,Level,Image,Left,Top,Position - BorderLeft - Left,Height,OffsetX,OffsetY);
  209.     LTP_DrawLevelImageRight(RPort,DrawInfo,Level,Image,Position + BorderLeft,Top,Left + Width - (Position + BorderLeft),Height,OffsetX,OffsetY);
  210. }
  211.  
  212.  
  213. /*****************************************************************************/
  214.  
  215.  
  216. ULONG __regargs
  217. LTP_LevelClassDraw(struct Image *Image,struct impDraw *DrawMsg,LevelImageInfo *Level)
  218. {
  219.     struct RastPort *RPort = DrawMsg -> imp_RPort;
  220.  
  221.     if(RPort -> Layer)
  222.         LockLayerRom(RPort -> Layer);
  223.  
  224.     LTP_DrawLevelImageComplete(Image,RPort,Level -> DrawInfo,Level,DrawMsg -> imp_Offset . X,DrawMsg -> imp_Offset . Y,DrawMsg -> imp_State == IDS_SELECTED);
  225.  
  226.     if(DrawMsg -> imp_State == IDS_DISABLED)
  227.     {
  228.         WORD    Left    = Image -> LeftEdge    + DrawMsg -> imp_Offset . X,
  229.             Top    = Image -> TopEdge    + DrawMsg -> imp_Offset . Y;
  230.  
  231.         LTP_SetPens(RPort,Level -> DrawInfo -> dri_Pens[BLOCKPEN],0,JAM1);
  232.  
  233.         SetAfPt(RPort,(UWORD *)&ghostingPat,1);
  234.         RectFill(RPort,Left,Top,Left + Image -> Width - 1,Top + Image -> Height - 1);
  235.         SetAfPt(RPort,NULL,0);
  236.     }
  237.  
  238.     if(RPort -> Layer)
  239.         UnlockLayerRom(RPort -> Layer);
  240.  
  241.     return(TRUE);
  242. }
  243.  
  244.  
  245. /*****************************************************************************/
  246.  
  247.  
  248. ULONG __regargs
  249. LTP_LevelClassSet(Class *class,struct Image *Image,struct opSet *SetMsg)
  250. {
  251.     LevelImageInfo    *Level = (LevelImageInfo *)INST_DATA(class,Image);
  252.     struct TagItem    *Item,*List,*PositionItem = NULL;
  253.     LONG         Width = Image -> Width - 2 * Level -> KnobWidth;
  254.  
  255.     List = SetMsg -> ops_AttrList;
  256.  
  257.     while(Item = NextTagItem(&List))
  258.     {
  259.         switch(Item -> ti_Tag)
  260.         {
  261.             case LVIA_Current:
  262.  
  263.                 Level -> Current = Item -> ti_Data;
  264.                 break;
  265.  
  266.             case LVIA_Max:
  267.  
  268.                 Level -> Max = Item -> ti_Data;
  269.                 break;
  270.  
  271.             case LVIA_Position:
  272.  
  273.                 PositionItem = Item;
  274.                 break;
  275.         }
  276.     }
  277.  
  278.     if(PositionItem)
  279.     {
  280.         LONG Position = (LONG)PositionItem -> ti_Data;
  281.  
  282.         if(Position < 0 || !Level -> Max)
  283.             Position = 0;
  284.         else
  285.         {
  286.             if(Position > Width)
  287.                 Position = Width;
  288.         }
  289.  
  290.         Level -> Position = Position;
  291.     }
  292.     else
  293.     {
  294.         if(Level -> Max)
  295.             Level -> Position = (Width * Level -> Current) / Level -> Max;
  296.         else
  297.             Level -> Position = 0;
  298.     }
  299.  
  300.     return(DoSuperMethodA(class,(Object *)Image,SetMsg));
  301. }
  302.  
  303.  
  304. /*****************************************************************************/
  305.  
  306.  
  307. ULONG __regargs
  308. LTP_LevelClassGet(Class *class,struct Image *Image,struct opGet *GetMsg)
  309. {
  310.     LevelImageInfo *Level = (LevelImageInfo *)INST_DATA(class,Image);
  311.  
  312.     switch(GetMsg -> opg_AttrID)
  313.     {
  314.         case LVIA_Current:
  315.  
  316.             *GetMsg -> opg_Storage = Level -> Current;
  317.  
  318.             return(TRUE);
  319.  
  320.         case LVIA_Max:
  321.  
  322.             *GetMsg -> opg_Storage = Level -> Max;
  323.  
  324.             return(TRUE);
  325.  
  326.         case LVIA_Position:
  327.  
  328.             *GetMsg -> opg_Storage = Level -> Position;
  329.  
  330.             return(TRUE);
  331.  
  332.         case LVIA_KnobWidth:
  333.  
  334.             *GetMsg -> opg_Storage = Level -> KnobWidth;
  335.  
  336.             return(TRUE);
  337.     }
  338.  
  339.     return(DoSuperMethodA(class,(Object *)Image,GetMsg));
  340. }
  341.  
  342.  
  343. /*****************************************************************************/
  344.  
  345.  
  346. ULONG __regargs
  347. LTP_LevelClassNew(Class *class,Object *object,struct opSet *SetMsg)
  348. {
  349.     LONG         Width        = 0,
  350.              Height     = 0;
  351.     UWORD         FontWidth    = 0;
  352.     LONG         Current    = 0,
  353.              Max        = 0;
  354.     struct DrawInfo *DrawInfo    = NULL;
  355.     struct TagItem    *List,
  356.             *Item;
  357.  
  358.     List = SetMsg -> ops_AttrList;
  359.  
  360.     while(Item = NextTagItem(&List))
  361.     {
  362.         switch(Item -> ti_Tag)
  363.         {
  364.             case IA_Width:
  365.  
  366.                 Width = Item -> ti_Data;
  367.                 break;
  368.  
  369.             case IA_Height:
  370.  
  371.                 Height = Item -> ti_Data;
  372.                 break;
  373.  
  374.             case LVIA_FontWidth:
  375.  
  376.                 FontWidth = Item -> ti_Data;
  377.                 break;
  378.  
  379.             case LVIA_DrawInfo:
  380.  
  381.                 DrawInfo = (struct DrawInfo *)Item -> ti_Data;
  382.                 break;
  383.  
  384.             case LVIA_Current:
  385.  
  386.                 Current = (LONG)Item -> ti_Data;
  387.                 break;
  388.  
  389.             case LVIA_Max:
  390.  
  391.                 Max = (LONG)Item -> ti_Data;
  392.                 break;
  393.         }
  394.     }
  395.  
  396.     if(Width && Height >= 4 && DrawInfo)
  397.     {
  398.         struct Image *Image;
  399.  
  400.         if(Image = (struct Image *)DoSuperMethodA(class,object,(Msg)SetMsg))
  401.         {
  402.             LevelImageInfo    *Level = (LevelImageInfo *)INST_DATA(class,Image);
  403.             WORD         QuarterWidth,
  404.                      KnobWidth,
  405.                      LevelHeight;
  406.  
  407.             QuarterWidth    = (FontWidth + 3) / 4,
  408.             KnobWidth    = 3 * QuarterWidth,
  409.             LevelHeight    = (KnobWidth * DrawInfo -> dri_Resolution . X) / DrawInfo -> dri_Resolution . Y;
  410.  
  411.             if(LevelHeight >= Height)
  412.                 LevelHeight = Height / 4;
  413.  
  414.             if(LevelHeight < 4)
  415.             {
  416.                 if(Height > 4)
  417.                     LevelHeight = 4;
  418.                 else
  419.                     LevelHeight = Height;
  420.             }
  421.  
  422.             Level -> KnobWidth    = KnobWidth;
  423.             Level -> KnobTop    = (Height - LevelHeight) / 2;
  424.             Level -> LevelHeight    = LevelHeight;
  425.             Level -> Max        = Max;
  426.             Level -> Current    = Current;
  427.             Level -> DrawInfo    = DrawInfo;
  428.  
  429.             if(Max)
  430.                 Level -> Position = ((Width - 2 * KnobWidth) * Current) / Max;
  431.             else
  432.                 Level -> Position = 0;
  433.  
  434.             return((ULONG)Image);
  435.         }
  436.     }
  437.  
  438.     return(NULL);
  439. }
  440.  
  441.  
  442. /*****************************************************************************/
  443.  
  444.  
  445. ULONG __saveds __asm
  446. LTP_LevelClassDispatcher(register __a0 Class *class,register __a2 Object *object,register __a1 Msg msg)
  447. {
  448.     switch(msg -> MethodID)
  449.     {
  450.         case IM_DRAW:
  451.  
  452.             return(LTP_LevelClassDraw((struct Image *)object,(struct impDraw *)msg,(LevelImageInfo *)INST_DATA(class,object)));
  453.  
  454.         case OM_SET:
  455.  
  456.             return(LTP_LevelClassSet(class,(struct Image *)object,(struct opSet *)msg));
  457.  
  458.         case OM_GET:
  459.  
  460.             return(LTP_LevelClassGet(class,(struct Image *)object,(struct opGet *)msg));
  461.  
  462.         case OM_NEW:
  463.  
  464.             return(LTP_LevelClassNew(class,object,(struct opSet *)msg));
  465.  
  466.         default:
  467.  
  468.             return(DoSuperMethodA(class,object,msg));
  469.     }
  470. }
  471. #endif    /* DO_LEVEL_KIND */
  472.